<template>
  <div class="home">
  <el-container>
    <el-header>
      <h1>后台管理系统</h1>
      <div>
        <span>欢迎：{{ username }} </span>
        <el-button @click="out">退出</el-button>
      </div>
    </el-header>
    <el-container>
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <div class="iscollspan" @click="isCollapse = !isCollapse">
          <p>|||</p>
        </div>
        <el-menu
          default-active="1"
          class="el-menu-vertical-demo"
          @open="handleOpen"
          @close="handleClose"
          :collapse="isCollapse"
          background-color="#333"
          text-color="#fff"
          active-text-color="#fff"
          :collapse-transition="false"
          :unique-opened="true"
        >
          <el-submenu v-for="v in menusList" :key="v.id" :index="v.id + ''">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span slot="title">{{ v.authName }}</span>
            </template>
            <el-menu-item
              v-for="vv in v.children"
              :key="vv.id"
              :index="vv.id + ''"
              >{{ vv.authName }}</el-menu-item
            >
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <el-breadcrumb separator-class="el-icon-arrow-right">
  <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
  <el-breadcrumb-item>活动管理</el-breadcrumb-item>
  <el-breadcrumb-item>活动列表</el-breadcrumb-item>
  <el-breadcrumb-item>活动详情</el-breadcrumb-item>
  </el-breadcrumb>
      </el-main>
    </el-container>
  </el-container>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import { menus } from "@/http/user.js";
export default {
  data() {
    return {
      isCollapse: false,
      menusList: []
    };
  },
  created() {
    this.getMenus();
  },
  computed: {
    ...mapGetters(["username"])
  },
  methods: {
    out() {
      this.$message({
        message: "退出成功",
        type: "success"
      });
      this.$router.push("/");
      this.$store.commit("user/DEL_TOKEN");
      this.$store.commit("user/DEL_USERNAME");
    },
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    async getMenus() {
      let res = await menus();
      console.log(res);
      this.menusList = res.data;
    }
  },
  components: {}
};
</script>
<style lang="scss">
.el-header {
  background-color: #333;
  color: white;
  line-height: 60px;
  display: flex;
  justify-content: space-between;
}

.el-aside {
  background-color: #333;
  color: #fff;
  height: calc(100vh - 60px);
}

.el-main {
  background-color: #fff;
  color: #333;
  height: calc(100vh - 60px);
}
.iscollspan {
  background: #4a5064;
  color: white;
  text-align: center;
}
</style>